package io.nuls.klines.config;

import io.nuls.klines.context.ServerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 启动时做一些操作
 *
 * @author: PierreLuo
 * @date: 2019-08-12
 */
@Component
public class AppInitializing implements InitializingBean {

    final Logger logger = LoggerFactory.getLogger(getClass());

    @Value("${app.binanceApi.host}")
    private String binanceApiHost;
    @Value("${app.sync.default-start-day}")
    private Long syncDefaultStartDay;
    @Value("${app.proxy.proxyHost}")
    private String proxyHost;
    @Value("${app.proxy.proxyPort}")
    private Integer proxyPort;
    @Value("${app.proxy.proxyMode}")
    private Boolean proxyMode;

    @Override
    public void afterPropertiesSet() throws Exception {
        logger.info("binance api host is {}", binanceApiHost);
        //logger.info("sync default start day is {}", syncDefaultStartDay);
        //TODO pierre 初始化配置
        if (proxyHost != null)
            ServerContext.proxyHost = proxyHost;
        if (proxyPort != null)
            ServerContext.proxyPort = proxyPort;
        if (proxyMode != null)
            ServerContext.proxyMode = proxyMode;
    }
}
